﻿using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace DefCore
{
    public class Font
    {
        public SpriteFont Fnt { get; set; }
        public string Location { get; set; }
        public string Name { get; set; }

        public Font(string name)
        {
            this.Name = name;
            this.Fnt = Objects.GameObject.Content.Load<SpriteFont>(string.Format(@"src\fonts\{0}", Name));
        }
    }
    
    public sealed class FontBin
    {
        //Singleton Pattern
        private static FontBin _Instance;
        public static FontBin Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new FontBin();

                return _Instance;
            }
        }

        //Fields
        private Dictionary<string, Font> _FontBank;

        //ctor
        protected FontBin()
        {
            _FontBank = new Dictionary<string, Font>();
        }

        //Methods
        public void Load()
        {
            DirectoryInfo dInfo = new DirectoryInfo(string.Format(@"{0}\src\fonts", Objects.GameObject.Content.RootDirectory));

            foreach (FileInfo s in dInfo.GetFiles())
            {
                try
                {
                    string name = s.Name.Split('.')[0];
                    _FontBank.Add(name, new Font(name));
                }
                catch (Exception e)
                { }
            }
        }

        public SpriteFont GetFnt(string name)
        {
            return _FontBank[name].Fnt;
        }
        public string GetLoc(string name)
        {
            return _FontBank[name].Location;
        }
    }
}
